﻿using Data;
using Infrastructure.States;
using TMPro;
using UI.Support;
using UnityEngine;

namespace UI
{
    public class EndGameWindow : BaseWindow
    {
        private GameStateMachine _stateMachine;
        [SerializeField] private TextMeshProUGUI _score;
        [SerializeField] private ButtonClick _okButton;
        private HeroState _state;

        public void Construct(GameStateMachine stateMachine, HeroState state)
        {
            _stateMachine = stateMachine;
            _state = state;
        }


        protected override void OnAwake() =>
            _okButton.Clicked += EndGame;

        public void ShowResult()
        {
            var score  =  _state.CurrentScore;
            _score.text  =   $"{score}";
        }

        private void EndGame() =>
            _stateMachine.Enter<LoadProgressState>();
    }
}